package parameter;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;

public class GetParameter {

	String host = null;		//每个网站的内容数据库服务器地址1

	public String getHost() {
		return host;
	}

	String dBName = null;	//每个网站的内容数据库服务器地址
	
	public String getdBName() {
		return dBName;
	}
	
	int tagBeginner = 0;	//tag表id排到多少，此次从多少开始

	public int getTagBeginner() {
		return tagBeginner;
	}
	
	int keywordsBeginner = 0; //从哪个id开始的关键词开始灌入到tag表里

	public int getKeywordsBeginner() {
		return keywordsBeginner;
	}
	
	int tagURLBeginner = 0;	//从access灌入tag-URL时，可以在这里设置从哪个id开始导入

	public int getTagURLBeginner() {
		return tagURLBeginner;
	}
	
	int contentATMBeginner = 0;

	public int getContentATMBeginner() {
		return contentATMBeginner;
	}
	
	int postIdBeginner = 0;
	
	public int getPostIdBeginner() {
		return postIdBeginner;
	}

	int insertCount = 0;
	
	public int getInsertCount() {
		return insertCount;
	}

	int contentIdBeginner = 0;
	
	public int getContentIdBeginner() {
		return contentIdBeginner;
	}

	String wpHost = null;
	
	public String getWpHost() {
		return wpHost;
	}

	String wpDataBaseName = null;

	public String getWpDataBaseName() {
		return wpDataBaseName;
	}
	
	int bandwidth = 0;
	
	public int getBandwidth() {
		return bandwidth;
	}
	
	String wordHost = null;

	public String getWordHost() {
		return wordHost;
	}
	
	String wordDB = null;

	public String getWordDB() {
		return wordDB;
	}
	
	int wycBeginner = 0;
	
	public int getWycBeginner() {
		return wycBeginner;
	}
	
	int wycCount = 0;
	
	public int getWycCount() {
		return wycCount;
	}
	
	String keywordCodeTranslatSourceDBListName = null;

	public String getKeywordCodeTranslatSourceDBListName() {
		return keywordCodeTranslatSourceDBListName;
	}
	
	String keywordCodeTranslatSourceDBFieldName = null;

	public String getKeywordCodeTranslatSourceDBFieldName() {
		return keywordCodeTranslatSourceDBFieldName;
	}
	
	public int translateYN = 0;
	
	public int getTranslateYN() {
		return translateYN;
	}

	public int wangzhiYN = 0;
	
	public int getWangzhiYN() {
		return wangzhiYN;
	}

	public int spiderURLYN = 0;
	
	public int getSpiderURLYN() {
		return spiderURLYN;
	}

	public int spiderYN = 0;
	
	public int getSpiderYN() {
		return spiderYN;
	}

	public int wycYN = 0;
	
	public int getWycYN() {
		return wycYN;
	}

	public int publishYN = 0;

	public int getPublishYN() {
		return publishYN;
	}

	public GetParameter() {

		String xmlpath = "library.xml";
		SAXBuilder builder = new SAXBuilder(false);
	/*	try {
			Document doc = builder.build(xmlpath);
			Element wycParameter = doc.getRootElement();
			List wycParameterlist = wycParameter.getChildren("host");
			for (Iterator iter = wycParameterlist.iterator(); iter.hasNext();) {
				Element getStrPar = (Element) iter.next();
				this.host = getStrPar.getAttributeValue("host");
				this.dBName = getStrPar.getChildTextTrim("dBName");
				this.translateYN = new Integer(getStrPar.getChildTextTrim("translateYN"));
				this.wangzhiYN = new Integer(getStrPar.getChildTextTrim("wangzhiYN"));
				this.spiderURLYN = new Integer(getStrPar.getChildTextTrim("spiderURLYN"));
				this.spiderYN = new Integer(getStrPar.getChildTextTrim("spiderURLYN"));
				this.wycYN = new Integer(getStrPar.getChildTextTrim("wycYN"));
				this.publishYN = new Integer(getStrPar.getChildTextTrim("publishYN"));
				
			}

		} */
		try {
			Document doc = builder.build(xmlpath);
			Element wycParameter = doc.getRootElement();
			List wycParameterlistaa = wycParameter.getChildren("aa");
			for(Iterator iteraa = wycParameterlistaa.iterator(); iteraa.hasNext();)
			{
				Element getStrParaa = (Element) iteraa.next();
			List wycParameterlist = getStrParaa.getChildren("host");
			for (Iterator iter = wycParameterlist.iterator(); iter.hasNext();) {
				Element getStrPar = (Element) iter.next();
				this.host = getStrPar.getAttributeValue("host");
				this.dBName = getStrPar.getChildTextTrim("dBName");
				this.translateYN = new Integer(getStrPar.getChildTextTrim("translateYN"));
				this.wangzhiYN = new Integer(getStrPar.getChildTextTrim("wangzhiYN"));
				this.spiderURLYN = new Integer(getStrPar.getChildTextTrim("spiderURLYN"));
				this.spiderYN = new Integer(getStrPar.getChildTextTrim("spiderURLYN"));
				this.wycYN = new Integer(getStrPar.getChildTextTrim("wycYN"));
				this.publishYN = new Integer(getStrPar.getChildTextTrim("publishYN"));
				
			}

		} }
		catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void TagAdd() {

		String xmlpath = "library.xml";
		SAXBuilder builder = new SAXBuilder(false);
		try {
			Document doc = builder.build(xmlpath);
			Element wycParameter = doc.getRootElement();
			List wycParameterlist = wycParameter.getChildren("tagAdd");
			for (Iterator iter = wycParameterlist.iterator(); iter.hasNext();) {
				Element getStrPar = (Element) iter.next();
				this.keywordsBeginner = new Integer(getStrPar.getAttributeValue("keywordsBeginner"));
				this.tagBeginner = new Integer(getStrPar.getChildTextTrim("tagBeginner"));
			}

		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void TagURLATM() {

		String xmlpath = "library.xml";
		SAXBuilder builder = new SAXBuilder(false);
		try {
			Document doc = builder.build(xmlpath);
			Element wycParameter = doc.getRootElement();
			List wycParameterlist = wycParameter.getChildren("tagURLATM");
			for (Iterator iter = wycParameterlist.iterator(); iter.hasNext();) {
				Element getStrPar = (Element) iter.next();
				this.tagURLBeginner = new Integer(getStrPar.getAttributeValue("tagURLATMBeginner"));
				
			}

		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void ContentATM() {

		String xmlpath = "library.xml";
		SAXBuilder builder = new SAXBuilder(false);
		try {
			Document doc = builder.build(xmlpath);
			Element wycParameter = doc.getRootElement();
			List wycParameterlist = wycParameter.getChildren("contentATM");
			for (Iterator iter = wycParameterlist.iterator(); iter.hasNext();) {
				Element getStrPar = (Element) iter.next();
				this.contentATMBeginner = new Integer(getStrPar.getAttributeValue("contentATMBeginner"));
				
			}

		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void Publish() {

		String xmlpath = "library.xml";
		SAXBuilder builder = new SAXBuilder(false);
		try {
			Document doc = builder.build(xmlpath);
			Element wycParameter = doc.getRootElement();
			List wycParameterlist = wycParameter.getChildren("publish");
			for (Iterator iter = wycParameterlist.iterator(); iter.hasNext();) {
				Element getStrPar = (Element) iter.next();
				this.insertCount = new Integer(getStrPar.getAttributeValue("insertCount"));
				this.postIdBeginner = new Integer(getStrPar.getChildText("postIdBeginner"));
				this.contentIdBeginner = new Integer(getStrPar.getChildText("contentIdBeginner"));
				this.wpHost = getStrPar.getChildTextTrim("wpHost");
				this.wpDataBaseName = getStrPar.getChildTextTrim("wpDataBaseName");
				
			}

		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void word() {

		String xmlpath = "library.xml";
		SAXBuilder builder = new SAXBuilder(false);
		try {
			Document doc = builder.build(xmlpath);
			Element wycParameter = doc.getRootElement();
			List wycParameterlist = wycParameter.getChildren("word");
			for (Iterator iter = wycParameterlist.iterator(); iter.hasNext();) {
				Element getStrPar = (Element) iter.next();
				this.bandwidth = new Integer(getStrPar.getChildText("bandwidth"));
				this.wordHost = getStrPar.getChildTextTrim("wordHost");
				this.wordDB = getStrPar.getChildTextTrim("wordDB");
				
			}

		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public void wyc() {

		String xmlpath = "library.xml";
		SAXBuilder builder = new SAXBuilder(false);
		try {
			Document doc = builder.build(xmlpath);
			Element wycParameter = doc.getRootElement();
			List wycParameterlist = wycParameter.getChildren("wyc");
			for (Iterator iter = wycParameterlist.iterator(); iter.hasNext();) {
				Element getStrPar = (Element) iter.next();
				this.wycBeginner = new Integer(getStrPar.getAttributeValue("wycBeginner"));
				this.wycCount = new Integer(getStrPar.getChildText("wycCount"));
					}

		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public void keywordCodeTranslat() {

		String xmlpath = "library.xml";
		SAXBuilder builder = new SAXBuilder(false);
		try {
			Document doc = builder.build(xmlpath);
			Element wycParameter = doc.getRootElement();
			List wycParameterlist = wycParameter.getChildren("keywordCodeTranslator");
			for (Iterator iter = wycParameterlist.iterator(); iter.hasNext();) {
				Element getStrPar = (Element) iter.next();
				this.keywordCodeTranslatSourceDBListName = getStrPar.getChildTextTrim("keywordCodeTranslatSourceDBListName");
				this.keywordCodeTranslatSourceDBFieldName = getStrPar.getChildTextTrim("keywordCodeTranslatSourceDBFieldName");
				this.translateBeginner = new Integer(getStrPar.getChildTextTrim("translateBeginner"));
			}

		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	String urlSpiderHead = null;
	
	public String getUrlSpiderHead() {
		return urlSpiderHead;
	}

	String urlSpiderFoot = null;
	
	public String getUrlSpiderFoot() {
		return urlSpiderFoot;
	}
	
	String cutSectionHead = null;
	
	public String getCutSectionHead() {
		return cutSectionHead;
	}
	
	String cutSectionFoot = null;

	public String getCutSectionFoot() {
		return cutSectionFoot;
	}
	
	int spiderURLTagBeginner = 0;

	public int getSpiderURLTagBeginner() {
		return spiderURLTagBeginner;
	}
	
	String titleTrimRex = null;

	public String getTitleTrimRex() {
		return titleTrimRex;
	}

	public void urlSpider() {

		String xmlpath = "library.xml";
		SAXBuilder builder = new SAXBuilder(false);
		try {
			Document doc = builder.build(xmlpath);
			Element wycParameter = doc.getRootElement();
			List wycParameterlist = wycParameter.getChildren("urlSpider");
			for (Iterator iter = wycParameterlist.iterator();iter.hasNext();) {
				Element getStrPar = (Element) iter.next();
				this.spiderURLTagBeginner = new Integer(getStrPar.getChildTextTrim("spiderURLTagBeginner"));
				this.urlSpiderHead = getStrPar.getChildTextTrim("urlSpiderHead");
				this.urlSpiderFoot = getStrPar.getChildTextTrim("urlSpiderFoot");
				this.cutSectionHead = getStrPar.getChildTextTrim("cutSectionHead");
				this.cutSectionFoot = getStrPar.getChildTextTrim("cutSectionFoot");
				this.titleTrimRex = getStrPar.getChildTextTrim("titleTrimRex");				
					}

		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void setLastSpiderBeginner(String lastSpiderBeginner) {

		String xmlpath = "library.xml";
		SAXBuilder builder = new SAXBuilder(false);
		try {
			Document doc = builder.build(xmlpath);
			Element wycParameter = doc.getRootElement();
			List wycParameterlist = wycParameter.getChildren("urlSpider");
			for (Iterator iter = wycParameterlist.iterator();iter.hasNext();) {
				Element getStrPar = (Element) iter.next();
				getStrPar.getChild("spiderURLTagBeginner").setText(lastSpiderBeginner);		
					}
			XMLOutputter outputter=new XMLOutputter();
			 outputter.output(doc,new FileOutputStream(xmlpath));

		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	int translateBeginner = 0;
	
	public int getTranslateBeginner() {
		return translateBeginner;
	}

	public void setTranslateBeginner(int translateBeginner) {

		String xmlpath = "library.xml";
		SAXBuilder builder = new SAXBuilder(false);
		try {
			Document doc = builder.build(xmlpath);
			Element wycParameter = doc.getRootElement();
			List wycParameterlist = wycParameter.getChildren("keywordCodeTranslator");
			for (Iterator iter = wycParameterlist.iterator();iter.hasNext();) {
				Element getStrPar = (Element) iter.next();
				getStrPar.getChild("translateBeginner").setText(Integer.toString(translateBeginner));		
					}
			XMLOutputter outputter=new XMLOutputter();
			 outputter.output(doc,new FileOutputStream(xmlpath));

		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public void setLastSpiderContentBeginner(String lastSpiderBeginner) {

		String xmlpath = "spiderParameter.xml";
		SAXBuilder builder = new SAXBuilder(false);
		try {
			Document doc = builder.build(xmlpath);
			Element wycParameter = doc.getRootElement();
			List wycParameterlist = wycParameter.getChildren("sourceSite");
			for (Iterator iter = wycParameterlist.iterator();iter.hasNext();) {
				Element sourceSite = (Element) iter.next();
				//sourceSite.getChild("spiderURLTagBeginner").setText(lastSpiderBeginner);		
				List contentSpiderList = sourceSite.getChildren("contentSpider");
				for(Iterator iter2 = contentSpiderList.iterator();iter2.hasNext();){
					Element contentSpider = (Element) iter2.next();
					contentSpider.getChild("titleTrimRex").setText("192.168.0.6");
				}
			}
			XMLOutputter outputter=new XMLOutputter();
			 outputter.output(doc,new FileOutputStream(xmlpath));

		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
